#include "IntervalList.h"
#include <cassert>
void IntervalList::push_front(GID_T KmerID)
{
	m_data.push_front(KmerID);
}

void IntervalList::push_back(GID_T KmerID)
{
	m_data.push_back(KmerID);
}
// vector<GINT64> IntervalList::GetMember()
// {
// 	return m_data;
// }

GID_T IntervalList::front() const
{
	return m_data.front();
}

GID_T IntervalList::back() const
{
	return m_data.back();
}

void IntervalList::concat(const IntervalList &IList)
{
	m_data.insert(m_data.end(), IList.m_data.begin(), IList.m_data.end());
	//for (GUINT32 i = 0; i < IList.m_data.size(); i++) {
	//	this->m_data.push_back(IList.m_data[i]);
	//}
}

void IntervalList::reverseConcat(const IntervalList &IList)
{
	GINT32 n=IList.m_data.size();
	for(GINT32 i=n-1;i>=0;i--)
		m_data.push_front(IList.m_data[i]);
}

bool IntervalList::contain(IntervalList& sub)
{
	if (m_data.size() < sub.m_data.size()) {
		return false;
	}
	for (GUINT32 i = 0; i <= m_data.size() - sub.m_data.size(); ++i) {
		GUINT32 j = 0;
		for (; j < sub.m_data.size(); ++j) {
			if (m_data[i + j] != sub.m_data[j]) {
				break;
			}
		}
		if (j == sub.m_data.size()) {
			return true;
		}
	}
	return false;
}

bool IntervalList::include(IntervalList& sub,int start)
{
	int i;
	int n=start+sub.GetSize();
	if(n<m_data.size())
	{
		int j=0;
		for(i=start;i<n;i++)
			if(m_data[i]!=sub.getElement(j++))
				break;
		if(i==n)
			return true;
		else
			return false;
	}
	return false;

}
//IntervalList IntervalList::intersect(IntervalList& list1, IntervalList& list2) const
//{
//	return IntervalList();
//}

//void IntervalList::resetCursor()
//{
//	m_iter = 0;
//}
//
//bool IntervalList::hasNext() 
//{
//	return m_iter < m_data.size();
//}
//
//GINT64 IntervalList::next()
//{
//	assert(hasNext());
//	return m_data[m_iter++];
//}

int IntervalList::GetSize()
{
	return m_data.size();
}

GINT64 IntervalList::getElement(int i)
{
	int size=m_data.size();
	if(i<size)
		return m_data[i];
	return -1;
}

deque<GID_T>::const_iterator IntervalList::begin()
{
	return m_data.begin();
}

deque<GID_T>::const_iterator IntervalList::end()
{
	return m_data.end();
}
